package face.array;

/**
 * @author spf
 * @date 2024/8/21
 * @time 19:00
 */

import java.util.Scanner;

/**
 * 开发商购买土地
 */
public class KaiFaShang {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        int sum = 0;
        int[][] num = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                num[i][j] = scanner.nextInt();
                sum += num[i][j];
            }
        }

        int count = 0;
        int result = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                count += num[i][j];

                if (j == m - 1) {
                    result = Math.min(result, Math.abs(sum - (count << 1)));
                }
            }
        }

        count = 0;
        for (int j = 0; j < m; j++) {
            for (int i = 0; i < n; i++) {
                count += num[i][j];
                if (i == n - 1) {
                    result = Math.min(result, Math.abs(sum - (count << 1)));
                }
            }
        }
        System.out.println(result);
        System.out.println(10-2<<1);
        scanner.close();
    }

}
